package zhoug.common.adapters.recycler;

import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;

import zhoug.common.R;

import androidx.annotation.NonNull;

/**
 * 1个文本适配器
 * @Author 35574
 * @Date 2020/8/7
 * @Description
 */
public abstract class TextAdapter<T> extends BaseRecyclerViewAdapter<T> {
    private int gravity= Gravity.CENTER;

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.common_list_item_text;
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = super.onCreateViewHolder(parent, viewType);
        ((TextView) baseViewHolder.itemView).setGravity(gravity);
        return baseViewHolder;
    }

    @Override
    public void onBindData(BaseViewHolder holder, T data, int position, int viewType) {
        if(data!=null){
            ((TextView) holder.itemView).setText(getText(data));
        }
    }

    public abstract String getText(T t);

    public void setGravity(int gravity) {
        this.gravity = gravity;
    }

}
